;	Original ISR code.
;	-----------------
;	Interrupt flags are sorted first. For the PWM 5 Period flag(s), the code run depends on the
;	flag "flags,wf_tbl_dir_f", directing whether a new sample for DAC 1 is taken in the
;	direction going UP or DOWN the sample table. Should the table pointer FSR0<H:L> be
;	indexed off either end of the table, the pointer is repositioned and the direction flag reversed.
;	The table ends are defined by labels "wf_tbl_top" and "wf_tbl_end".
;	For the SPI 1 peripheral, no code is currently required.
;
isr_start							; Interrupt sorting.
	movlb	bank_0						; ( Bank 0.)
	btfsc	PIR6,PWM5IF					; Is there a PWM5 Interrupt flag,
	bra	isr_pwm5_start					; If NO - skip, else jump.
	movlb   bank_27						; ( Bank 27.)
	btfsc   PWM5INTF,PRIF					; Is there a PWM5 Period Interrupt ?
	bra	isr_pwm5_start						; If NO - skip, else jump.
	movlb   bank_0						; ( Bank 0.)
	btfsc   PIR1,SSP1IF					; Is there an SPI1 Interrupt ?
	bra	isr_spi1_start						; If NO - skip, else jump.
	retfie							; Return from Interrupt.
    
isr_pwm5_start						; Pointer Incrementing or Decrementing ?
	movlb   bank_27						; ( Bank 27.)
	bcf	PWM5INTF,PRIF					; Clear the PWM5 Period Interrupt flag,
	movlb   bank_0						; ( Bank 0.)
	bcf	PIR6,PWM5IF					; and the PWM5 group PIR6 flag.
	btfsc   flags,wf_tbl_dir_f				; Is the pointer direction Decrement ? ( Flag = 0.)
	bra	isr_wf_tbl_inc						; If YES - skip, else jump for Increment.
isr_wf_tbl_dec						; Decrement the table pointer UP the sample table.
	moviw   FSR0--						; Fetch the current sample and decrement the pointer. Samples go from -ve to +ve values.
	movlb   bank_11						; ( Bank 11.)
	movwf   DAC1REFH
	bsf	DACLD,DAC1LD					; Output the new sample value.
	movlw   LOW wf_tbl_top					; Check the pointer position.
	subwf   FSR0L,W
	btfsc   STATUS,C					; Is the pointer off the TOP of the table ?
	retfie								; If NO - return, else skip to reset the pointer,
	movlw   LOW wf_tbl_top + 1				; one sample DOWN from the TOP,
	movwf   FSR0L
	movlb   bank_0						; ( Bank 0.)
	bsf	flags,wf_tbl_dir_f				; and reverse the direction flag. ( 1 = DOWN.)
	retfie							; Return from Interrupt.
    
isr_wf_tbl_inc						; Increment the table pointer DOWN the sample table.
	moviw   FSR0++						; Fetch the current sample and increment the pointer. Samples go from +ve to -ve values.
	movlb   bank_11						; ( Bank 11.)
	movwf   DAC1REFH
	bsf	DACLD,DAC1LD					; Output the new sample value.
	movf	FSR0L,W						; Check the pointer position.
	sublw   LOW wf_tbl_end
	btfsc   STATUS,C					; Is the pointer off the END of the table ?
	retfie								; If NO - return, else skip to reset the pointer,
	movlw   LOW wf_tbl_end - 1				; one sample UP from the END,
	movwf   FSR0L
	movlb   bank_0						; ( Bank 0.)
	bcf	flags,wf_tbl_dir_f				; and reverse the direction flag. ( 0 = UP.)
	retfie							; Return from Interrupt. 
    
isr_spi1_start
	bcf	PIR1,SSP1IF					; Clear the SPI1 Interrupt flag.
    
	retfie							; Return from Interrupt.
 